﻿using System;

class AreNumberBiggerThanNeighbors
{
    static bool ValidatePosition(int[] arr,int position)
    {
        if (position<0)
        {
            Console.WriteLine("Entered position is incorrect!");
            Console.Write("Enter positive integer for position:");
            return false;
        }
        else if (position>arr.Length-1)
        {
            Console.WriteLine("Entered position is out of range!");
            Console.Write("Enter number smaller than {0}:",arr.Length-1);
            return false;
        }
        else
        {
            return true;
        }
    }

    static string CountNeighbors(int[] arr,int position)
    {
        if (position==0)
        {
            return "1 right";
        }
        else if(position==arr.Length-1)
        {
            return "1 left";
        }
        else
        {
            return "2";
        }

    }

    static string ComareWithNeighbors(int[] arr,int position)
    {
        string result;
        string neighbors = CountNeighbors(arr,position);

        if (neighbors=="1 right")
        {
            if (arr[position]>arr[position+1])
            {
                result="bigger than right neighbor";
            }
            else
            {
                result = "smaller than right neighbor";
            }
        }
        else if (neighbors=="1 left")
        {
            if (arr[position]>arr[position-1])
            {
                result = "bigger than left neighbor";
            }
            else
            {
                result = "smaller than left neighbor";
            }
        }
        else
        {
            if (arr[position]>arr[position-1] && arr[position]>arr[position+1])
            {
                result = "bigger than both neighbor";
            }
            else if (arr[position]<arr[position-1] && arr[position]>arr[position+1])
            {
                result = "smaller than left neighbor and bigger than right neighbor";
            }
            else if (arr[position] > arr[position - 1] && arr[position] < arr[position + 1])
            {
                result = "bigger than left neighbor and smaller than right neighbor";
            }
            else
            {
                result = "smaller than both neighbor";
            }
        }
        return result;
    }

    static void Main()
    {
        Console.Write("Enter position:");
        int position=int.Parse(Console.ReadLine());

        int[] arr = { 5, 1, -2, 6, 3 };

        string resultCopmare;
        bool areValaidInputs=false;

        while (areValaidInputs == false) 
        {
            areValaidInputs = ValidatePosition(arr, position);
            if (areValaidInputs==false)
            {
                position = int.Parse(Console.ReadLine());
            }
        }
        
        resultCopmare=ComareWithNeighbors(arr, position);

        Console.WriteLine("Element on position:{0} is {1}",position,resultCopmare);
    }
}

